#!/bin/sh
##################################################################
#钟建军
#2023/01/30
#
#从参数1（远程ETL服务器ip）上，根据参数2（ETL日志文件目录）获取日志目录和文件情单
#
##################################################################
usage(){
	echo "Usage : getEtlLogDir.sh remoteIP [dir]"
	echo "   eg.: getEtlLogDir.sh 30.3.3.111 ma_job"
	exit -1
}
#参数检查或帮助显示
[ $# -eq 0 ] && usage
[ $1 == "-h" -o $1 == "--help" ] && usage


ipaddr=$1
dir=$2

etlpath=/home/ftpapp/FTP_Engine/

etlpath_tmp=`ssh -q $ipaddr source '.bash_profile; echo $ETLPATH'`
[ $etlpath_tmp ] && etlpath=$etlpath_tmp

basedir=$etlpath/log/
result=`ssh -q $ipaddr "ls $basedir/$dir > /dev/null 2>&1 ;"' echo $?'`
if [ ${result} -eq 0 ];then
    ssh -q $ipaddr "ls -lt $basedir/$dir | grep -v ^total | head -500"
elif [ ${result} -eq 2 ];then
    echo '在服务器['$ipaddr']上不存在目录['$basedir'/'$dir']'
else
    echo '在服务器['$ipaddr']上检查目录['$basedir'/'$dir']错误，错误码:'${result}
fi
exit ${result}
